/*
 * Copyright (c) 2009 XMock contributors
 * This program is made available under the terms of the Apache License.
 */
package org.xmock.controller;

import java.util.Properties;

import org.apache.log4j.Logger;


public class MockProperties 
{
	private static final Logger logger = Logger.getLogger(MockProperties.class);
	private static MockProperties instance;
	private static String propFileName = "xmock.properties";
	
	private Properties properties;
	
	private MockProperties()
	{
		init();
	}
	
	private void init()
	{
		String propFileLoc = "META-INF/xmock/" + propFileName;
		ClassLoader classloader = null;
        try
        {
            classloader = Thread.currentThread().getContextClassLoader();
        }
        catch(Exception exception)
        {
            logger.error("Mock properties loading error", exception);
            return;
        } 
        try
        {
            java.io.InputStream inputstream = null;
            if(classloader == null)
                inputstream = ClassLoader.getSystemResourceAsStream(propFileLoc);
            else
                inputstream = classloader.getResourceAsStream(propFileLoc);
            if(inputstream != null)
            {
            	properties = new Properties();
                properties.load(inputstream);
            }
        }
        catch(Exception exception2) { }
	}
	
	public static MockProperties getInstance()
	{
		if(instance == null)
		{
			instance = new MockProperties();
		}
		return instance;
	}
	
	public String getProperty(String key)
	{
		if(properties == null)
		{
			return null;
		}
		return properties.getProperty(key);
	}

}
